package com.example.shiwu.adapter;

import android.content.Context;
import android.database.DataSetObserver;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.shiwu.R;
import com.example.shiwu.db.model.CvsBean;
import com.example.shiwu.db.vo.SendVo;

import java.util.ArrayList;
import java.util.List;

public class CvsAdapter extends BaseAdapter implements View.OnClickListener {

    private static final String TAG = CvsAdapter.class.getSimpleName();

    private Context mContext;
    private int resourceId;
    private List<CvsBean> listItems = new ArrayList<CvsBean>();

    private List<CvsBean> mList = new ArrayList<CvsBean>();

    public CvsAdapter(Context context, List<CvsBean> listItems, int resource) {
        this.mContext = context;
        this.mList = listItems;
        this.resourceId = resource;
    }


    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        final CvsViewHolder holder;
        if (convertView == null) {
            view = LayoutInflater.from(parent.getContext()).inflate(resourceId, parent, false);
            holder = new CvsViewHolder(view);
            view.setTag(holder);
        }else {
            view = convertView;
            holder = (CvsAdapter.CvsViewHolder) view.getTag();
            holder.samplingRate.setText(mList.get(position).getSamplingRate() + "");
            holder.cycle.setText(mList.get(position).getCycle() + "");
            holder.dataPoint.setText(mList.get(position).getDataPoint() + "");
            holder.A.setText(mList.get(position).getA() + "");
            holder.B.setText(mList.get(position).getB() + "");
            holder.M.setText(mList.get(position).getM() + "");
            holder.N.setText(mList.get(position).getN() + "");
            holder.TX_V.setText(mList.get(position).getTX_V() + "");
            holder.TX_I.setText(mList.get(position).getTX_I() + "");
            holder.RX_V.setText(mList.get(position).getRX_V() + "");
        }
        return view;
    }

    @Override
    public void onClick(View v) {

    }

//    @Override
//    public View getView(ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(mContext).inflate(R.layout.send_details_list_item_cvs, parent, false);
//        return new CvsViewHolder(view);
//    }
//
//    @Override
//    public void onBindViewHolder(CvsViewHolder holder, int position) {
//        holder.samplingRate.setText(mList.get(position).getSamplingRate() + "");
//        holder.cycle.setText(mList.get(position).getCycle() + "");
//        holder.dataPoint.setText(mList.get(position).getDataPoint() + "");
//        holder.A.setText(mList.get(position).getA() + "");
//        holder.B.setText(mList.get(position).getB() + "");
//        holder.M.setText(mList.get(position).getM() + "");
//        holder.N.setText(mList.get(position).getN() + "");
//        holder.TX_V.setText(mList.get(position).getTX_V() + "");
//        holder.TX_I.setText(mList.get(position).getTX_I() + "");
//        holder.RX_V.setText(mList.get(position).getRX_V() + "");
//    }
//
//    @Override
//    public int getItemCount() {
//        return mList == null ? 0 : mList.size();
//    }
//

    class CvsViewHolder {

        TextView samplingRate,cycle,dataPoint,A,B,M,N,TX_V,TX_I,RX_V;

        public CvsViewHolder(View itemView) {
            samplingRate = itemView.findViewById(R.id.cvs_item_SamplingRate);
            cycle = itemView.findViewById(R.id.cvs_item_Cycle);
            dataPoint = itemView.findViewById(R.id.cvs_item_DataPoint);
            A = itemView.findViewById(R.id.cvs_item_A);
            B = itemView.findViewById(R.id.cvs_item_B);
            M = itemView.findViewById(R.id.cvs_item_M);
            N = itemView.findViewById(R.id.cvs_item_N);
            TX_V = itemView.findViewById(R.id.cvs_item_TX_V);
            TX_I = itemView.findViewById(R.id.cvs_item_TX_I);
            RX_V = itemView.findViewById(R.id.cvs_item_RX_V);
        }
    }
}
